//
//  ClassListController.m
//  BOSS-SOOC
//
//  Created by apple on 16/8/19.
//  Copyright © 2016年 Gcx. All rights reserved.
//

#import "ClassListController.h"
#import "ClassListModel.h"
#import "classTableView/ClassTableView.h"
#import "classListCell/DetailListTableViewCell.h"

@interface ClassListController()<ClassTableViewDelegate>{

    NSString *_yxid;
    NSString *_xsm;
    NSInteger _pageNumber;
}

@property (nonatomic,strong) NSArray *modelArray;


@end

@implementation ClassListController

- (void)viewDidLoad{

    [super viewDidLoad];
    
    [self.navbar setTitle:_xsm];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self creatTableViewAndGetSourceData];
}

- (void)creatTableViewAndGetSourceData{
    
    ClassTableView *tableView = [[ClassTableView alloc]initWithFrame:CGRectMake(0, 64, SIZEWIDTH, SIZEHEIGHT-64) style:UITableViewStyleGrouped];
    
    tableView.myDelegate = self;
    
    [self.view addSubview:tableView];
    
    _pageNumber = 1;

    ClassListModel *listModel = [[ClassListModel alloc]init];
    
    [listModel getListData:1 yxid:_yxid];
    
    tableView.myBlock = ^(BOOL isRefresh){
        
        if (isRefresh == YES) {
            
            _pageNumber = 1;
            
        } else {
            
            _pageNumber++;
        }
        
        [listModel getListData:_pageNumber yxid:_yxid];
        
    };
    /**
     *  校内列表的回调
     */
    listModel.succeedBlock = ^(id succeedValue){
        
        _modelArray = succeedValue;
        
        tableView.sourceArr = succeedValue;
    };
    
    listModel.failBlock = ^(id failValue){
        
        NSLog(@"error == %@", failValue);
    };


}

- (instancetype)initDataWithServerData:(NSString *)yxid andXsm:(NSString *)xsm{

    _yxid = yxid;
    _xsm = xsm;
    
    return self;
}


/**
 *  cell的点击事件
 */
- (void)classTableViewSeleted:(ClassTableView *)classTableView resuletString:(NSString *)resultString Row:(int)row{

    ClassListModel *listModel = [[ClassListModel alloc]init];
    [self navigationCanDragBack:YES];
    [listModel detailWithListModel:_modelArray[row] WithViewController:self];

}

- (NSArray *)modelArray{

    if (_modelArray) {
        
        _modelArray = [NSArray array];
    }
    
    return _modelArray;
}

@end
